package baiqitun.stupro.common.exception;

import baiqitun.stupro.common.exception.enums.ExceptionEnumParent;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统异常基类
 * @author kedaji
 */
@Getter
@Setter
public class StuproException extends RuntimeException {
    private String code;
    private Map<String, Object> parameters;

    public StuproException(){

    }

    public StuproException(ExceptionEnumParent exceptionEnum){
        super(exceptionEnum.getMsg());
        this.code = exceptionEnum.getCode();
    }

    public StuproException put(String key, Object value){
        if (parameters == null){
            parameters = new HashMap<>();
        }
        parameters.put(key, value);
        return this;
    }

    public StuproException put(Class<?> clazz, String key, Object value){
        if (parameters == null){
            parameters = new HashMap<>();
        }
        parameters.put(clazz.getSimpleName()+"."+key, value);
        return this;
    }
}
